<template>
<div class="times">
    <div class="time">
        <div class="last" v-show="isShowLast" @click="handelLast"></div>
        <div class="conter">{{startTime}} 到 {{endTime}}</div>
        <div class="next" v-show="isShowNext" @click="handelNext"></div>
    </div>
    <div class="setTime" @click="handelShowPicker">{{timerType}}&nbsp;<i class="iconfont">&#xe637;</i></div>
</div>
</template>

<script>
import {string,time } from '@/util/public'
export default {
    name:'times',
    props:['timerType'],
    data(){
        return {
            isShowLast:true,
            isShowNext:false
        }
    },
    computed:{
        startTime(){
            return this.$store.state.studentAppraise.scoreInfo_startTime;
        },
        endTime(){
            return this.$store.state.studentAppraise.scoreInfo_endTime;
        },
        timeType(){
            return this.$store.state.studentAppraise.scoreInfo_timeType;
        }
    },
    methods:{
        handelShowPicker(){
            this.$emit('handelShowPicker')
        },
        handelLast(){
            if(this.timeType == 1){
                let getPrevWeek = time.getPrevWeek(this.endTime);
                this.$store.state.studentAppraise.scoreInfo_startTime = getPrevWeek[0];
                this.$store.state.studentAppraise.scoreInfo_endTime = getPrevWeek[1];
                this.isShowNext = true;
            }
            if(this.timeType == 2){
                this.$store.state.studentAppraise.scoreInfo_startTime = time.getPreMonth(this.startTime);
                this.$store.state.studentAppraise.scoreInfo_endTime = time.getPreMonthEnd(this.startTime);
                this.isShowNext = true;
            }
            this.$emit('handelGeData');
        },
        handelNext(){
            let defaultTime = time.getCurrentWeek();  
            if(this.timeType == 1){
                let getNextvWeek = time.getNextvWeek(this.endTime);
                this.$store.state.studentAppraise.scoreInfo_startTime = getNextvWeek[0];
                this.$store.state.studentAppraise.scoreInfo_endTime = getNextvWeek[1];

                let today = Number(string.replaceAll(String(time.getNow(0)),'-',''));  
                let endTime = Number(string.replaceAll(String(this.endTime),'-','')); 
                if(endTime >= today){
                    this.$store.state.studentAppraise.scoreInfo_startTime = defaultTime[0];
                    this.$store.state.studentAppraise.scoreInfo_endTime = time.getNow(0);
                    this.isShowNext = false;
                }
            }
            if(this.timeType == 2){
                this.$store.state.studentAppraise.scoreInfo_startTime = time.getNextMonth(this.startTime);
                this.$store.state.studentAppraise.scoreInfo_endTime = time.getNextMonthEnd(this.endTime);

                let today = Number(string.replaceAll(String(time.getNow(0)),'-',''));  
                let endTime = Number(string.replaceAll(String(this.endTime),'-','')); 
                if(endTime >= today){
                    this.$store.state.studentAppraise.scoreInfo_startTime = time.getNow(2)
                    this.$store.state.studentAppraise.scoreInfo_endTime = time.getNow(0);
                    this.isShowNext = false;
                }
            }
            this.$emit('handelGeData');
        },
        handelInit(){
            if(this.timeType == 1){
                this.isShowLast = true;
                this.isShowNext = false;
                let defaultTime = time.getCurrentWeek()
                this.$store.state.studentAppraise.scoreInfo_startTime = defaultTime[0];
                this.$store.state.studentAppraise.scoreInfo_endTime = defaultTime[1];

                let today = Number(string.replaceAll(String(time.getNow(0)),'-',''));  
                let endTime =  Number(string.replaceAll(String(defaultTime[1]),'-',''));
                if(endTime > today){
                    this.$store.state.studentAppraise.scoreInfo_endTime = time.getNow(0);
                }
            }
            if(this.timeType == 2){
                this.isShowLast = true;
                this.isShowNext = false;
                this.$store.state.studentAppraise.scoreInfo_startTime = time.getNow(2);
                this.$store.state.studentAppraise.scoreInfo_endTime = time.getNow(0);
            }
            if(this.timeType == 3){
                this.isShowLast = false;
                this.isShowNext = false;
            }
        }
    },
    activated(){
        this.handelInit();
    }
}
</script>

<style lang="less" scoped>
 @import url('../../../../assets/css/iconfont.css');
.times{
    padding:0.3rem 0;
    position: relative;
    .time{
        display: flex;
        justify-content:center;
        .last{
            width:0.32rem;
            height:0.32rem;
            background: url(../../images/scoreInfo1.png) center no-repeat;
            background-size:100%;
        }
        .next{
            width:0.32rem;
            height:0.32rem;
            background: url(../../images/scoreInfo2.png) center no-repeat;
            background-size:100%;
        }
        .conter{
            font-size:0.26rem;
            color:#000;
            padding:0 0.3rem;
        }
    }
    .setTime{
        padding: 0 0.2rem;
        height: 0.5rem;
        line-height:0.5rem;
        background-color:#fff;
        border-radius:0.5rem;
        font-size: 0.26rem;
        color:#666;
        text-align: center;
        position: absolute;
        right: 0.25rem;
        top: 0.25rem;
        .iconfont{
            font-size:0.22rem;
        }
    }
}
</style>

